#include "mainwindow.h"
#include "ui_mainwindow.h"
#include "ffmpegutils.h"
#include "audioresample.h"
MainWindow::MainWindow(QWidget *parent)
    : QMainWindow(parent)
    , ui(new Ui::MainWindow)
{
    ui->setupUi(this);
}

MainWindow::~MainWindow()
{
    delete ui;
}


void MainWindow::on_pushButton_clicked()
{

    if(recordPCMThread == nullptr) {

        recordPCMThread = new RecordPCMThread(this);
        ui->pushButton->setText("暂定");

        connect(recordPCMThread,&QThread::finished,[this](){

            ui->pushButton->setText("录音");
            recordPCMThread = nullptr;
        });

        recordPCMThread->start();
    }else {

        recordPCMThread->requestInterruption();
    }

}

void MainWindow::on_playButton_clicked()
{


    if(playPCMThread == nullptr) {

        playPCMThread = new PlayPCMThread(this);
        ui->playButton->setText("暂定");

        connect(playPCMThread,&QThread::finished,[this](){

            ui->playButton->setText("播放");
            playPCMThread = nullptr;
        });

        playPCMThread->start();
    }else {

        playPCMThread->requestInterruption();
    }

}

void MainWindow::on_pushButton_2_clicked()
{

    WAVHeadStructure wavHeadStructure;

    wavHeadStructure.numChannels = 2;
    wavHeadStructure.sampleRate = 44100;
    wavHeadStructure.bitPerSample = 32;
    wavHeadStructure.audioFormat = 3;

    FFMPEGUtils::pcmTowav(wavHeadStructure,"/Users/tgy/Documents/ffmpeg/audio/recode_pcm_01.pcm","/Users/tgy/Documents/ffmpeg/audio/recode_pcm_001.wav");

}

void MainWindow::on_resampleButton_clicked()
{

    AudioResample* audioResample = new AudioResample(this);
    audioResample->start();
}
